<template>
  <div class="container">
    <!-- 面包屑导航 -->
    <div class="breadcrumb">
      <el-breadcrumb separator="">
        <el-breadcrumb-item
          ><div class="div1">基本配置</div></el-breadcrumb-item
        >
        <el-breadcrumb-item
          ><div class="div2">职位权限管理</div></el-breadcrumb-item
        >
      </el-breadcrumb>
    </div>
    <!-- 面包屑导航 teamManage -->
    <!-- 添加团队 -->
    <div class="content">
      <p class="header">添加职位</p>
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="职位名称">
          <el-input
            maxlength="32"
            v-model="formInline.name"
            placeholder="请输入职位名称"
          ></el-input>
        </el-form-item>

        <el-form-item label="职位编码">
          <el-input
          maxlength="32"
            v-model="formInline.code"
            placeholder="请输入职位名称"
          ></el-input>
        </el-form-item>

        <el-form-item label="职位描述">
          <el-input
            maxlength="64"
            v-model="formInline.remark"
            placeholder="请输入职位名称"
          ></el-input>
        </el-form-item>

        <el-form-item>
          <el-button
            type="primary"
            @click="addposition"
            v-if="parArray.indexOf('zwadd') != -1"
            >添加职位</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <!-- 添加团队 -->
    <!-- 管理团队 -->
    <div class="manage">
      <p class="header">职位管理</p>
      <div class="table">
        <vxe-table align="center" keep-source :data="tableData.list">
          <vxe-table-column title="序号" type="seq"></vxe-table-column>
          <vxe-table-column field="positionName" title="职位名称" width="200">
            <template slot-scope="scope">
              <el-input v-model="scope.row.positionName"></el-input>
            </template>
          </vxe-table-column>
          <vxe-table-column
            title="职位编码"
            field="positionCode"
          ></vxe-table-column>
          <vxe-table-column title="职位描述" field="remark"></vxe-table-column>
          <vxe-table-column
            title="职位状态"
            field="statusName"
          ></vxe-table-column>
          <vxe-table-column
            title="创建时间"
            field="createdTime"
          ></vxe-table-column>

          <vxe-table-column title="操作">
            <template slot-scope="scope">
              <div class="optain">
                <el-tooltip
                  class="item"
                  effect="dark"
                  content="保存"
                  placement="top-start"
                >
                  <p
                    @click="fixPosition(scope.row)"
                    v-if="parArray.indexOf('zwbc') != -1"
                  >
																		保存
                    <!-- <img src="../../../assets/baocun.png" alt="" /> -->
                  </p>
                </el-tooltip>
                <el-tooltip
                  class="item"
                  effect="dark"
                  content="删除"
                  placement="top-start"
                >
                  <p
                    @click="delect(scope.row, scope.$index)"
                    v-if="parArray.indexOf('zwdelect') != -1"
                  >
																		删除
                    <!-- <img src="../../../assets/delect.png" alt="" /> -->
                  </p>
                </el-tooltip>
                <!-- <el-tooltip class="item" effect="dark" content="设定权限" placement="top-start"> -->
                <!-- <p><el-button type='primary' @click='limitsSelects'>设定权限</el-button></p> -->
                <!-- </el-tooltip>		 -->
              </div>
            </template>
          </vxe-table-column>
        </vxe-table>
        <div class="page" v-if="tableData.totalNum >= 8">
          <div class="block">
            <el-pagination
              background=""
              @current-change="handleCurrentChange"
              :current-page.sync="currentPage1"
              :page-size="1"
              layout="total, prev, pager, next"
              prev-text="上一页"
              next-text="下一页"
              :total="tableData.totalPage"
            >
            </el-pagination>
          </div>
        </div>
      </div>
    </div>
    <!-- 管理客户等级 -->
  </div>
</template>

<script>
export default {
  data() {
    return {
      formInline: {
        name: "",
        code: "",
        remark: "",
      },
      select: [],
      selectType: [],
      tableData: [],
      currentPage1: 1,
      bumenId: "",
      lxId: "",
      limits: "",
      parArray: [],
    };
  },
  created() {
    this.positionList("1"); //查询职位列表
    // 权限设定判断 normsCode
    this.limits = JSON.parse(sessionStorage.getItem("limit"));
    const params = this.limits.buttonTreeDto.filter(
      (item) => item.menuCode === "positionCode"
    );
    params[0].buttonList.forEach((item) => {
      this.parArray.push(item.code);
    });
    // 权限设定判断 normsCode
  },
  activated() {
    // this.positionList("1");//查询职位列表
  },
  methods: {
    handleCurrentChange(val) {
      this.positionList(`${val}`);
    },
    // 添加职位权限
    addposition() {
      console.log(this.formInline.position);
      this.axios
        .post(
          "/sys/v1/position/add",
          {
            request: {
              positionName: this.formInline.name,
              positionCode: this.formInline.code,
              remark: this.formInline.remark,
            },
            version: "",
          },
          {
            headers: {
              isLoading: false,
            },
          }
        )
        .then((res) => {
          // console.log(res)
          if (res.code == 0) {
            this.$message.success("添加成功");
            this.positionList("1"); //查询职位列表
          } else {
            this.$message.error(res.message);
          }
        });
    },
    // 添加职位权限	 end
    limitsSelects() {
      this.$router.push({ name: "limitsSelects" });
    },
    // 职位列表
    positionList(pageNo) {
      this.axios
        .post("/sys/v1/position/list", {
          request: {
            pageNo: pageNo,
            pageSize: 8,
            positionName: "",
            positionCode: "",
          },
          version: "",
        })
        .then((res) => {
          console.log(res);
          if (res.code == 0) {
            this.tableData = res.data;
          } else {
            this.$message.error(res.message);
          }
        });
    },
    // 职位列表
    // 修改职位名称start
    fixPosition(row) {
      this.axios
        .post(
          "/sys/v1/position/update",
          {
            request: {
              id: row.id,
              positionName: row.positionName,
              positionCode: row.positionCode,
              remark: row.remark,
              userId: sessionStorage.getItem("user_id"),
            },
            version: "",
          },
          {
            headers: {
              isLoading: false,
            },
          }
        )
        .then((res) => {
          // console.log('修改数据')
          // console.log(res)
          if (res.code == 0) {
            this.$message.success("修改成功");
            this.positionList("1");
          } else {
            this.$message.error(res.message);
          }
        });
    },
    // 修改职位名称end
    /***删除职位***/
    delect(row, index) {
      this.$confirm("确定要删除该职位吗, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.axios
            .post(
              "/sys/v1/position/delete",
              {
                request: {
                  id: row.id,
                  userId: sessionStorage.getItem("user_id"),
                },
                version: "",
              },
              {
                headers: {
                  isLoading: false,
                },
              }
            )
            .then((res) => {
              console.log(res);
              if (res.code == 0) {
                this.tableData.list.splice(index, 1);
                this.positionList("1");
                this.$message({
                  message: "删除成功",
                  type: "success",
                });
              } else {
                this.$message.error(res.message);
              }
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    /***删除职位 end***/
  },
};
</script>

<style scoped lang="scss">
.div1 {
  margin-left: -16px;
  background: url(../../../assets/breadcrumb2.png);
  width: 120px;
  height: 30px;
  text-align: center;
  line-height: 30px;
  color: #2d7edf;
}
.div2 {
  margin-left: -16px;
  background: url(../../../assets/breadcrumb1.png);
  width: 120px;
  height: 30px;
  text-align: center;
  line-height: 30px;
  color: #fff;
}
.div3 {
  margin-left: -8px;
  background: url(../../../assets/breadcrumb3.png);
  width: 120px;
  height: 30px;
  text-align: center;
  line-height: 30px;
  color: #2d7edf;
}
.content {
  padding: 10px;
  background: #fff;
  .el-button {
    padding: 6px 10px;
  }
}
.header {
  font-size: 16px;
  color: #2d7edf;
  padding-bottom: 10px;
  border-bottom: 1px solid #eee;
}
.demo-form-inline {
  margin-top: 10px;
}
/deep/.el-input__inner {
  height: 30px;
  line-height: 30px;
}
.manage {
  margin-top: 20px;
  padding: 10px;
  background: #fff;
}
/deep/.has-gutter .cell {
  text-align: center;
  color: #2d7ddf;
}
/deep/.cell {
  text-align: center;
}
.name {
  font-size: 16px;
  color: #2d7edf;
  margin: 10px 0;
}
.optain {
  width: 100%;
  text-align: center;
  p {
    display: inline-block;
    vertical-align: middle;
    // margin-left: 20px;
				margin:0 10px;
				color:#2D7DDF;
    img {
      width: 18px;
      height: 20px;
      margin-top: 8px;
    }
  }
}
.page {
  text-align: right;
  margin-top: 20px;
  span {
    font-size: 15px;
    color: #666;
    display: inline-block;
    margin-left: 10px;
    vertical-align: middle;
  }
  .el-pagination {
    display: inline-block;
    vertical-align: middle;
  }
}
.vxe-header--row {
  background: #fff;
}
</style>
